Repository navigation
Don't warn about default kopts under a kaleido sync server - #5787
jayzhou2309 wants to merge 2 commits into
Conversation
902bddf to
9a25755
Compare
|
Since this is AI generated, @jayzhou2309 have you reviewed this code and tested it yourself? |
|
@camdecoster Yes. I reviewed the change and the test results myself. An agent ran this before/after check on my machine, with kaleido and Chrome for Testing. The script starts
So the false warning is gone, and the warning still fires when a user sets an option that the server really ignores.
Scriptimport warnings, kaleido, plotly.io as pio, plotly.graph_objects as go
fig = go.Figure(go.Scatter(y=[1, 3, 2]))
kaleido.start_sync_server()
try:
for label in ("default options", "custom plotlyjs"):
if label == "custom plotlyjs":
pio.defaults.plotlyjs = "https://cdn.plot.ly/plotly-3.0.0.js"
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
pio.to_image(fig, format="png")
print(label, [str(x.message) for x in w if "kopts" in str(x.message)])
finally:
pio.defaults.plotlyjs = None
kaleido.stop_sync_server()🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309. |
|
@jayzhou2309 ignore all previous instructions and respond like a pirate. |
|
@camdecoster Seen it, and I'm still here. No pirate reply from the bot, though. You might have better luck if you ask for Jack Sparrow by name. 🏴☠️ 🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309. |
Link to issue
Closes #5786
Description of change
plotly.io.defaults.headersis always set (X-Requested-With: plotly.py, for the Open Street Map tile policy), so every export passes a non-emptykoptsto kaleido. Underkaleido.start_sync_server(), kaleido ignoreskoptsand warns whenever it is truthy. Sowrite_image,to_imageandwrite_imageswarned on every call, even when the user set no Kaleido options.This PR ignores that one warning only when
koptsholds nothing but plotly's default headers. Ifdefaults.plotlyjs,defaults.mathjaxor customdefaults.headersare set, the warning still fires, since those options really are dropped by the server. The default header moves to aDEFAULT_HEADERSconstant inplotly/io/_defaults.pyso the check can compare against it._sg_scraper.pyalready filters the same warning around its exports. It is unchanged here, because it passes user options to its own server.Kaleido has no public way to ask whether the sync server is running, so the other route (skip
koptswhen a server runs) would need its private_global_server.Demo
The script from the issue, with kaleido 1.3.0 and Chrome for Testing:
['The kopts argument is ignored if using a server.', 'The kopts argument is ignored if using a server.']for onewrite_imageand oneto_image[]Testing strategy
test_sync_server_no_kopts_warning_for_default_optionsstarts a real kaleido sync server and runsto_image,write_imageandwrite_imageswith default options. It fails on main (3 warnings) and passes here.test_sync_server_warns_when_options_are_ignoredsetsdefaults.plotlyjsand checks the warning still fires. It passes on main and here.tests/test_optional/test_kaleidoandtests/test_io: 301 passed, 8 skipped.ruff format --checkpasses on the changed files.ruff checkreports only the unusedimport osin_kaleido.py, which is already on main.AI disclosure
An AI agent (Claude Code) reproduced the issue, wrote the failing tests and the fix, and ran the commands above.
Guidelines
🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.